package com.gexiaobao.pigeon.ui.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.widget.AppCompatTextView
import com.gexiaobao.pigeon.R

/**
 * @author:hxw
 * @date  :2022/12/8
 * @desc  :
 */
class DialogPigeonMasterName(context: Context?) : RxDialog(context!!) {

    private lateinit var sureView: AppCompatTextView
    private lateinit var name1: AppCompatTextView
    private lateinit var name2: AppCompatTextView
    private lateinit var tvLine: AppCompatTextView
    private var masterName = ""

    init {
        initView()
    }

    @SuppressLint("MissingInflatedId")
    private fun initView() {
        val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_pigeon_master_name, null)
        sureView = dialogView.findViewById(R.id.tv_dialog_pigeon_master_name_sure)
        name1 = dialogView.findViewById(R.id.tv_dialog_pigeon_master_name1)
        name2 = dialogView.findViewById(R.id.tv_dialog_pigeon_master_name2)
        tvLine = dialogView.findViewById(R.id.tv_dialog_pigeon_line)

        name1.setOnClickListener {
            masterName = name1.text.toString()
        }

        name2.setOnClickListener {
            masterName = name2.text.toString()
        }

        sureView.setOnClickListener {
            if (onNameClick != null) {
                onNameClick!!.setOnNameClickListener(masterName)
            }
        }
        setContentView(dialogView)
    }

    fun getName1Text(): String {
        return name1.text.toString().trim()
    }

    fun getName2Text(): String {
        return name2.text.toString().trim()
    }

    fun setName1(mName1: String) {
        if (mName1.isEmpty()) {
            name1.visibility = View.GONE
            tvLine.visibility = View.GONE
            return
        }
        tvLine.visibility = View.VISIBLE
        name1.visibility = View.VISIBLE
        name1.text = mName1
    }

    fun setName2(mName2: String) {
        if (mName2.isEmpty()) {
            name2.visibility = View.GONE
            tvLine.visibility = View.GONE
            return
        }
        name2.text = mName2
    }

    fun setName1Listener(listener: View.OnClickListener?) {
        name1.setOnClickListener(listener)
    }

    fun setName2lListener(listener: View.OnClickListener?) {
        name2.setOnClickListener(listener)
    }

    interface OnNameClickListener {
        fun setOnNameClickListener(content: String)
    }

    private var onNameClick: OnNameClickListener? = null

    fun setOnItemClickListener(onNameClick: OnNameClickListener) {
        this.onNameClick = onNameClick
    }

}